﻿using System;
using System.IO;
using BestHTTP.JSON;

namespace Networking.Runtime
{
    [Serializable]
    public struct DownLoadFileData
    {
        public string[] fileUrl;
        public long fileSize;
        public string fileMd5;
        public string filePath;

        public override string ToString()
        {
            return Json.Encode(this);
        }
        
        public  bool IsValid()
        {
            return !string.IsNullOrEmpty(this.filePath) && !string.IsNullOrEmpty(this.fileMd5) && this.fileSize > 0 && (this.fileUrl != null && this.fileUrl.Length > 0);
        }

        public  bool IsFileDownloaded()
        {
            return File.Exists(this.filePath)
                   && DownLoadExtensions.GetFileSize(this.filePath) == this.fileSize
                   && this.fileMd5.Equals(DownLoadExtensions.GetMD5HashFromFile(this.filePath), StringComparison.OrdinalIgnoreCase);
        }
    } 
}



